import os
import sys
import download,image,captcha

def test(url,di_name):
	if not os.path.exists(di_name):
		os.mkdir(di_name)
	os.chdir(di_name)

	for i in range(1,5):
		filename = str(i)+'.gif'
		data = download.url_to_image_data(url)
		img_file = open(filename,'wb+')
		img_file.write(data)
		img = image.image_data_to_tiff(data)
		##img.show()
		img.convert('RGBA').save('bin_'+str(i)+'.tif')
		text = captcha.image_to_text(img)
		print("value:" +text)
if __name__ == '__main__':
	url = 'http://personal.tianma168.com/UserManage/ImgCode.aspx?8194436103'
	di_name = '/Users/zwx/Documents/captchaTest'
	test(url,di_name)
